<template>
  <div>
    <el-row class="operate-padding border">
      <el-button @click="dialogTableVisible = true" class="button-text-color">
        添加排期
      </el-button>
    </el-row>
    <!-- 模态 -->
    <el-row>
      <el-dialog
        v-model="dialogTableVisible"
        title="添加排期"
        class="model-121"
      >
        <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          :rules="rules"
          label-width="120px"
          class="demo-ruleForm"
          :size="formSize"
          status-icon
        >
          <el-form-item label="场馆选择" prop="region">
            <el-select v-model="ruleForm.region" placeholder="选择场馆">
              <el-option label="Zone one" value="shanghai" />
              <el-option label="Zone two" value="beijing" />
            </el-select>
          </el-form-item>
          <el-form-item label="场地" prop="region1">
            <el-select v-model="ruleForm.region1" placeholder="选择场地">
              <el-option label="Zone one" value="shanghai" />
              <el-option label="Zone two" value="beijing" />
            </el-select>
          </el-form-item>
          <el-form-item label="课程起始时间" prop="region1">
            <div class="example-basic">
              <el-time-picker v-model="value1" placeholder="00:00:00" />
              <el-time-picker
                v-model="value2"
                arrow-control
                placeholder="00:00:00"
                class="time-select-1"
              />
            </div>
          </el-form-item>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column label="星期一">
              <template #default>
                <el-select v-model="ruleForm.region3" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region4"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期二">
              <template #default>
                <el-select v-model="ruleForm.region5" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region6"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期三">
              <template #default>
                <el-select v-model="ruleForm.region7" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region8"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期四">
              <template #default>
                <el-select v-model="ruleForm.region9" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region10"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="星期五">
              <template #default>
                <el-select v-model="ruleForm.region11" placeholder="选择教练">
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
                <el-select
                  v-model="ruleForm.region12"
                  placeholder="选择教练"
                  class="select-pading"
                >
                  <el-option label="杨健" value="杨健" />
                  <el-option label="王宇" value="王宇" />
                  <el-option label="蒋旗" value="蒋旗" />
                  <el-option label="周朝洪" value="周朝洪" />
                  <el-option label="李佳会" value="李佳会" />
                </el-select>
              </template>
            </el-table-column>
          </el-table>
          <el-form-item>
            <el-button type="primary" @click="submitForm(ruleFormRef)"
              >Create</el-button
            >
            <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-row>
    <el-row class="lessons-padding1">
      <el-button type="primary" class="button-text-color"
        ><router-link to="/mainView/teamManagement/ScheduleView/CalendarView"
          >日历</router-link
        ></el-button
      >
      <el-button class="button-text-color2"
        ><router-link to="/mainView/teamManagement/ScheduleView/ListView"
          >列表</router-link
        ></el-button
      >
    </el-row>
    <el-table
      :data="state.tableData"
      border
      style="width: 100%"
      :header-cell-style="{ background: '#f9fafc', color: '#606266' }"
    >
      <el-table-column prop="time1" label="开始时间" width="120" />
      <el-table-column label="星期一" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.monday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.monday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.monday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.monday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.monday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期二" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.tuesday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.tuesday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.tuesday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.tuesday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.tuesday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期三" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.wednesday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.wednesday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.wednesday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.wednesday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.wednesday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期四" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.thursday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.thursday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.thursday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.thursday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.thursday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期五" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.friday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.friday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.friday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.friday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.friday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期六" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.saturday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.saturday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.saturday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.saturday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.saturday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
      <el-table-column label="星期天" width="180">
        <template #default="scope">
          <span class="line-break"
            >结束时间：<span class="color">{{
              scope.row.sunday.endTime
            }}</span></span
          >
          <span class="line-break"
            >团课：<span class="color">{{
              scope.row.sunday.className
            }}</span></span
          >
          <span class="line-break"
            >教练：<span class="color">{{
              scope.row.sunday.coachName
            }}</span></span
          >
          <span class="line-break"
            >约课人数：<span class="color">{{
              scope.row.sunday.number
            }}</span></span
          >
          <span class="line-break"
            >实到人数：<span class="color">{{
              scope.row.sunday.signNumber
            }}</span></span
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted, toRefs } from "vue";
import { findCourseList } from "../../http/api";
import { ElMessage, ElMessageBox } from "element-plus";
import router from "../../router";
import type { FormInstance, FormRules } from "element-plus";
// 表格
var state = reactive({ tableData: [] });
var obj1 = {
  time1: "8:30",
  monday: {},
  tuesday: {},
  wednesday: {},
  thursday: {},
  friday: {},
  saturday: {},
  sunday: {},
};
var obj2 = {
  time1: "10:00",
  monday: {},
  tuesday: {},
  wednesday: {},
  thursday: {},
  friday: {},
  saturday: {},
  sunday: {},
};
var obj3 = {
  time1: "12:30",
  monday: {},
  tuesday: {},
  wednesday: {},
  thursday: {},
  friday: {},
  saturday: {},
  sunday: {},
};
var obj4 = {
  time1: "14:00",
  monday: {},
  tuesday: {},
  wednesday: {},
  thursday: {},
  friday: {},
  saturday: {},
  sunday: {},
};
// 获取团课课程列表
onMounted(() => {
  lessonsList();
});
// 获取团课列表函数
var firstTime = [];
var secondTime = [];
var thirdTime = [];
var fourTime = [];
const lessonsList = () => {
  findCourseList({ startDate: "10-17" }).then((res) => {
    console.log(res);
    res.forEach((el, index) => {
      if (el.startTime == "8:30") {
        firstTime.push(el);
      } else if (el.startTime == "10:00") {
        secondTime.push(el);
      } else if (el.startTime == "12:30") {
        thirdTime.push(el);
      } else {
        fourTime.push(el);
      }
    });
    console.log(firstTime);
    lessonsList2(firstTime, obj1);
    lessonsList2(secondTime, obj2);
    lessonsList2(thirdTime, obj3);
    lessonsList2(fourTime, obj4);
    console.log(state.tableData);
  });
};
const lessonsList2 = (a, b) => {
  a.forEach((el, index) => {
    if (el.week == "星期1") {
      b.monday = el;
    } else if (el.week == "星期2") {
      b.tuesday = el;
    } else if (el.week == "星期3") {
      b.wednesday = el;
    } else if (el.week == "星期4") {
      b.thursday = el;
    } else if (el.week == "星期5") {
      b.friday = el;
    } else if (el.week == "星期6") {
      b.saturday = el;
    } else {
      b.sunday = el;
    }
  });
  state.tableData.push(b);
};

// 模态表单
const dialogTableVisible = ref(false);
const value1 = ref();
const value2 = ref();
const formSize = ref("default");
const ruleFormRef = ref<FormInstance>();
const ruleForm = reactive({
  region: "",
  region1: "",
  region2: "",
  region3: "",
  region4: "",
  region5: "",
  region6: "",
  region7: "",
  region8: "",
  region9: "",
  region10: "",
  region11: "",
  region12: "",
  region13: "",
  region14: "",
  region15: "",
  region16: "",
  region17: "",
  region18: "",
});

const rules = reactive<FormRules>({
  region: [
    {
      required: true,
      message: "Please select Activity zone",
      trigger: "change",
    },
  ],
  region1: [
    {
      required: true,
      message: "Please select Activity zone",
      trigger: "change",
    },
  ],
});

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!", fields);
    }
  });
};

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
};
// 表格
const tableData = [
  {
    date: "2016-05-03",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
];
</script>
<style scoped>
.el-table .cell {
  white-space: pre-line;
}
.line-break {
  display: block;
  color: rgb(169, 168, 168);
}
.color {
  color: #409eff;
}
.border {
  padding: 10px;
  border-radius: 5px;
  background-color: #ecf5ff;
  border: 1px solid #cccccc;
}
.button-text-color {
  background-color: #409eff !important;
  color: white !important;
}
.lessons-padding1 {
  padding: 10px 0;
}
</style>
